package com.xinlu.common.taglib;

import javax.servlet.jsp.JspException;

public class ShowHidden extends BaseTag {

	// 画面のＩＤ番号
	private String pageId;

	private String doAction;

	private String expand;

	public int doStartTag() throws JspException {
		
		try {
			StringBuffer sb = new StringBuffer();
			sb.append("<input type=\"hidden\" name=\"pageId\" id=\"pageId\" value=\"" + pageId + "\">");
//			if (doAction != null) {
				sb.append("<input type=\"hidden\" name=\"doAction\" id=\"doAction\" value=\"" + doAction + "\">");
//			}
			if (expand != null) {
				String[] expands = expand.split(";");
				if (expands != null && expands.length > 0) {
					for (int i = 0; i < expands.length; i++) {
						String expand = expands[i];
						String[] splitExpands = expand.split(":");

						String key = splitExpands[0];
						String value = splitExpands.length == 2 ? splitExpands[1] : null;

						sb.append("<input type=\"hidden\" name=\"" + key + "\" id=\"" + key + "\" ");
						if (value != null) {
							sb.append("value=\"" + value + "\" ");
						}
						sb.append(">");
					}
				}

			}

			pageContext.getOut().print(sb.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public String getPageId() {
		return pageId;
	}

	public void setPageId(String pageId) {
		this.pageId = pageId;
	}

	public String getDoAction() {
		return doAction;
	}

	public void setDoAction(String doAction) {
		this.doAction = doAction;
	}

	public String getExpand() {
		return expand;
	}

	public void setExpand(String expand) {
		this.expand = expand;
	}

}
